<template>
  <div>
    <template>
      <div style="padding-top: 10px;text-align: center">
        <el-alert
          title="提示语："
          type="info"
          :description="welMsg">
        </el-alert>
      </div>
    </template>
    <div class="panel panel-default" style="width: 100%;margin-top: 20px;">
      <div class="panel-heading" style="width: 100%"><b>配置集列表</b></div>
      <div class="panel-body">
        <div class="table-responsive" style="width: 100%">
          <table class="table table-bordered  table-striped table-hover table-condensed" id="fields_table">
            <tbody>
            <tr style="background-color: #E5E9F2;">
              <th style="text-align: center;padding-top: 13px">编号</th>
              <th style="text-align: center;padding-top: 13px">配置集标识</th>
              <th style="text-align: center;padding-top: 13px">配置集描述</th>
              <th style="width: 200px;text-align: center;padding-top: 10px">
                操作
                <el-tooltip effect="light" content="新增配置集" placement="top" :enterable="false">
                  <el-button :plain="true" type="success" size="small" @click="push">
                    <router-link to="/addcfgMap">新增</router-link>
                  </el-button>
                </el-tooltip>
              </th>
            </tr>
            <template v-if="cfgMaps.length > 0">
              <tr v-for="item in cfgMaps">
                <td style="text-align: center;vertical-align:middle" class="info">{{item.id}}</td>
                <td style="text-align: center;vertical-align:middle" >{{item.code}}</td>
                <td style="text-align: center;vertical-align:middle" >{{item.description}}</td>
                <td style="text-align: center;vertical-align:middle">
                  <div>
                    <el-button type="info" size="small">
                      <router-link :to="{name:'editcfgMap',params:item}">编辑</router-link>
                    </el-button>
                    <el-button type="danger" size="small" @click="delcfgMap(item)">删除</el-button>
                  </div>
                </td>
              </tr>
            </template>
            <tr v-else="">无数据</tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<style>
  td {
    text-align: center;
    vertical-align: middle;
  }
  .cell{
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    line-height: 24px;
    padding-left: 18px;
    padding-right: 18px;
  }
</style>

<script>
  import {mapState, mapMutations} from 'vuex';
  import fetch from "../../store/uacc_api";
  export default {
    data: function () {
      return {}
    },
    computed:{
      ...mapState(['cfgMaps','currentUser']),
      welMsg:function () {
        let user = this.$store.state.currentUser;
        if(user.nickName || user.nickName == ""){
          return user.lastName+", 欢迎您来到配置中心-配置集查询页面，在这里您可以对配置集进行新增,修改,删除操作";
        }else{
          return user.nickName+", 欢迎您来到配置中心-配置集查询页面，在这里您可以对配置集进行新增,修改,删除操作";
        }
      }
    },
    methods: {
      ...mapMutations(['editCfgMaps']),
      push(){
      },
      delcfgMap(val){
        let me = this;
        let param = {'id': val.id};
        fetch.deleteConfigStruct(param).then(function (res) {
          if (res.success) {
            me.initCfgMaps();
            me.$message({
              showClose: true,
              type: 'success',
              message: '删除配置集成功'
            });
          }else{
            me.$message({
              showClose: true,
              message: res.errorMessage,
              type: 'error'
            });
          }
        })
      },
    initCfgMaps(){
      let me = this;
      fetch.queryAllStructs().then(function (res) {
        if (res.success) {
          me.editCfgMaps(res.data);
        }
      })
    }
    }
  }
</script>
